#include <windows.h>
#include <stdio.h>
#include "CoordinateCal.h"

typedef void (*Coordinate)(point *pointlist, int Dim, int clusterN, double *A);

double data1[][5] = {
    {4.815584699675992, 9.942959701930075, 2.180749915863726, 12.790539011159952, 4.021936329981384},
    {9.945688475855851, 7.94566421098489, 12.760083170682247, 11.220247960451042, 12.778992720682743},
    {7.830392499529268, 9.091291842723374, 11.776371180392946, 12.120588691978066, 5.286782223119492},
    {0.5900455916994564, 8.448848169547395, 0.5255767794615335, 10.374916555596014, 4.686719377867854},
    {9.600759067746338, 12.91082884287538, 10.417864519742512, 9.50843690659103, 9.490567306697573},
    {2.599100281700802, 2.6747919402437215, 6.884214664912809, 4.5564780113847085, 0.6133219735383015},
    {12.996451102334808, 11.614553200069855, 4.148298396123962, 12.70115021863799, 7.366268993048537},
    {12.675183117163778, 0.2705771012354916, 0.025049188331461525, 12.473560479086599, 6.515080592643308},
    {11.359561041588229, 6.554229274814861, 9.925142965942957, 9.128075407405099, 12.900489421562002},
    {9.32002041123401, 4.899737734063642, 2.3439926107279367, 2.5854775237731342, 11.657938608676321},
};

double data2[][5] = {
    {19.938867666565184, 10.459058205193106, 18.674016415227555, 29.285333091114865, 23.644384740040614},
    {29.22867665019986, 20.34120235559569, 28.820486424946758, 38.51762808698431, 37.15918767006854},
    {28.133024939522524, 18.072619735452086, 25.638646581869565, 33.35692207298697, 34.20664722722007},
    {14.700026184519304, 6.1576471335214, 13.378394829442579, 21.75203886024399, 15.59354997180975},
    {28.707540132500753, 20.57568011439425, 26.858656710883988, 38.86780905310822, 34.58837825883561},
    {11.912596162005656, 7.45917526729578, 10.699106299013858, 11.38310273694541, 14.769299418843612},
    {26.026685463404753, 19.950435272535508, 27.090550256832696, 41.189001133324524, 32.564955491471686},
    {14.389186154939054, 11.46580879001764, 20.233517727754545, 28.614325125126406, 23.233191759959208},
    {25.123056601338213, 19.08342428878163, 25.6273710818048, 36.18903737079879, 32.37191797947412},
    {12.446273412145759, 12.296365195628713, 14.929836537091933, 24.781819412471734, 16.353481363852833},
};

point pinot[] = {
    {.src = data1[0],
     .dst = data2[0]},
    {.src = data1[1],
     .dst = data2[1]},
    {.src = data1[2],
     .dst = data2[2]},
    {.src = data1[3],
     .dst = data2[3]},
    {.src = data1[4],
     .dst = data2[4]},
    {.src = data1[5],
     .dst = data2[5]},
    {.src = data1[6],
     .dst = data2[6]},
    {.src = data1[7],
     .dst = data2[7]},
    {.src = data1[8],
     .dst = data2[8]},
    {.src = data1[9],
     .dst = data2[9]}};

#define N 5
int main()
{
    HINSTANCE hinstLib;
    Coordinate ProcAdd;
    BOOL fFreeResult;
    // Load the DLL
    hinstLib = LoadLibrary("./CoordinateCal.dll");
    if (hinstLib != NULL)
    {
        // Get the function address
        ProcAdd = (Coordinate)GetProcAddress(hinstLib, "CoordinateCal");
        if (NULL != ProcAdd)
        {
            // Call the function
            double M[(N + 1) * (N + 1)];
            CoordinateCal(pinot, N, sizeof(pinot) / sizeof(pinot[0]), M);
            for (int i = 0; i < N + 1; i++)
            {
                for (int j = 0; j < N + 1; j++)
                {
                    printf("%f ", M[i * (N + 1) + j]);
                }
                printf("\n");
            }
        }
        else
        {
            printf("Could not locate the function.\n");
        }
        // Free the DLL module
        fFreeResult = FreeLibrary(hinstLib);
    }
    else
    {
        printf("Could not load the DLL.\n");
    }

    return 0;
}